﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Soundelle.SoundPlayer
{
    public class WavFilePlayer
    {
        private System.Media.SoundPlayer WavPlayer = null;

        ~WavFilePlayer()
        {
            StopSound();
        }

        public void PlaySound(string WavFileName, bool IsLoop)
        {
            if (WavPlayer != null)
                StopSound();

            WavPlayer = new System.Media.SoundPlayer(WavFileName);

            if (IsLoop)
                WavPlayer.PlayLooping();
            else
               WavPlayer.Play();
        }

        public void StopSound()
        {
            if (WavPlayer != null)
            {
                WavPlayer.Stop();
                WavPlayer.Dispose();
                WavPlayer = null;
            }
        }
    }
}
